package com.qifenqian.turbot.module.adapter.restaurant

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.qifenqian.turbot.R
import com.qifenqian.turbot.config.TurbotEnum
import com.qifenqian.turbot.module.entity.response.restaurant.RestaurantTableEntity
import com.qifenqian.turbot.util.Lcat
import kotlinx.android.synthetic.main.item_table_info.view.*

/**
 * @author H
 * @createTime 2018/12/20 08:53
 * @description 餐桌信息的item
 * @see
 * @since
 */
class TableInfoAdapter(list: List<RestaurantTableEntity.Table>) : BaseQuickAdapter<RestaurantTableEntity.Table, BaseViewHolder>(R.layout.item_table_info, list) {

    override fun convert(helper: BaseViewHolder?, table: RestaurantTableEntity.Table?) {
        val view = helper!!.itemView
        view.tv_item_table_info_id.text = table!!.tableNo
        view.tv_item_table_info_people_num.text =
                if (table.minNumberOfPeople != 0 || table.maxNumberOfPeople != 0)
                    "${table.minNumberOfPeople}-${table.maxNumberOfPeople}人"
                else
                    "请输入人数"
        view.rb_item_table_info_hall.isChecked = table.tableType == TurbotEnum.TYPE_HALL.type
        view.rb_item_table_info_balcony.isChecked = table.tableType == TurbotEnum.TYPE_BALCONY.type
        view.rg_item_table_info_type.setOnCheckedChangeListener { group, checkedId ->
            when (checkedId) {
                R.id.rb_item_table_info_hall    -> {
                    table.tableType = TurbotEnum.TYPE_HALL.type
                }
                R.id.rb_item_table_info_balcony -> {
                    table.tableType = TurbotEnum.TYPE_BALCONY.type
                }
            }
            Lcat.a("tableInfoEntity", table)
        }
//        tvItemTableInfoPeopleNumber.isClickable = tvItemTableInfoPeopleNumber.text.toString() == "请输入人数"
        if (view.tv_item_table_info_people_num.text.toString() == "请输入人数") {
            view.tv_item_table_info_people_num.setOnClickListener {
                if (onEditPersonNumberListener != null) {
                    onEditPersonNumberListener!!.onEdit(helper.layoutPosition, table, view.tv_item_table_info_people_num)
                }
            }
        }
    }

    private var onEditPersonNumberListener: OnEditPersonNumberListener? = null

    fun setOnEditPersonNumberListener(listener: OnEditPersonNumberListener) {
        onEditPersonNumberListener = listener
    }

    interface OnEditPersonNumberListener {
        fun onEdit(position: Int, table: RestaurantTableEntity.Table?, tvItemTableInfoPeopleNumber: TextView)
    }
}